package com.qfedu.mall.service.Impl;

import com.qfedu.mall.beans.vo.SpellGroupVO;
import com.qfedu.mall.common.vo.ResStatus;
import com.qfedu.mall.common.vo.ResultVO;
import com.qfedu.mall.mapper.SpellGroupMapper;
import com.qfedu.mall.service.SpellGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
public class SpellGroupServiceImpl implements SpellGroupService {
    @Autowired
    private SpellGroupMapper spellGroupMapper;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultVO insertByUser1(SpellGroupVO spellGroupVO) {
        final ResultVO resultVO = new ResultVO();
        int a = spellGroupMapper.insertUser1(spellGroupVO);
        if(a>0){
            List<SpellGroupVO> users = spellGroupMapper.getPinkByUser1(spellGroupVO.getUser1(),spellGroupVO.getProductId());
            resultVO.setData(users);
            resultVO.setCode(ResStatus.OK);
            resultVO.setMsg("success");
            return resultVO;
        }else {
            List<SpellGroupVO> users = spellGroupMapper.getPinkByUser1(spellGroupVO.getUser1(),spellGroupVO.getProductId());
            resultVO.setData(users);
            resultVO.setCode(ResStatus.NO);
            resultVO.setMsg("插入失败");
            return resultVO;
        }
    }

    @Override
    public ResultVO updateByUser2(SpellGroupVO spellGroupVO) {
        final ResultVO resultVO = new ResultVO();
        int a = spellGroupMapper.updateUser2(spellGroupVO);
        if(a>0){
            List<SpellGroupVO> users = spellGroupMapper.getPinkByUser2(spellGroupVO.getGroupId());
            resultVO.setData(users);
            resultVO.setCode(ResStatus.OK);
            resultVO.setMsg("success");
            return resultVO;
        }else {
            List<SpellGroupVO> users = spellGroupMapper.getPinkByUser2(spellGroupVO.getGroupId());
            resultVO.setData(users);
            resultVO.setCode(ResStatus.NO);
            resultVO.setMsg("插入失败");
            return resultVO;
        }
    }
}
